package drds.server.sqlparser.parser;

/**
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class CharType {

	/**
	 * 判断首字符是否是合法标识符
	 */
	private final static boolean[] firstIdentifierFlags = new boolean[256];
	static {
		for (char $char = 0; $char < firstIdentifierFlags.length; ++$char) {
			if ($char >= 'A' && $char <= 'Z') {
				firstIdentifierFlags[$char] = true;
			} else if ($char >= 'a' && $char <= 'z') {
				firstIdentifierFlags[$char] = true;
			}
		}
		firstIdentifierFlags['_'] = true;

	}

	public static boolean isFirstIdentifierChar(char $char) {
		if ($char <= firstIdentifierFlags.length) {
			return firstIdentifierFlags[$char];
		} else {
			return false;
		}
	}

	/**
	 * 判断字符是否是合法标识符
	 */
	private final static boolean[] identifierFlags = new boolean[256];
	static {
		for (char $char = 0; $char < identifierFlags.length; ++$char) {
			if ($char >= 'A' && $char <= 'Z') {
				identifierFlags[$char] = true;
			} else if ($char >= 'a' && $char <= 'z') {
				identifierFlags[$char] = true;
			} else if ($char >= '0' && $char <= '9') {
				identifierFlags[$char] = true;
			}
		}
		identifierFlags['_'] = true;
	}

	public static boolean isIdentifierChar(char $char) {
		if ($char <= identifierFlags.length) {
			return identifierFlags[$char];
		} else {
			return false;
		}
	}

	/**
	 * 只支持英文空格
	 */
	public static boolean isWhitespace(char $char) {
		return $char == ' ';
	}

	/**
	 * 判断是否是数字
	 */
	public static boolean isDigit(char $char) {
		return $char >= '0' && $char <= '9';
	}

}
